package system

import (
	"github.com/gin-gonic/gin"
	"server/model/common/response"
	sysModel "server/model/system"
	sysRequest "server/model/system/request"
	sysService "server/service/system"
)

type OptLogApi struct {
}

//日志列表接口
func (o *OptLogApi) Index(c *gin.Context) {
	//搜索条件
	p := &sysRequest.SysOptLogGetList{}
	if err := c.ShouldBind(p); err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	//日志列表
	logList, total, err := sysService.OperationLogServiceApp.GetList(p)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	//权限列表
	permList, err := sysService.PermissionServiceApp.GetAll()
	permTreeOriginList := ([]*sysModel.SysPermission)(nil)
	for _, permission := range permList {
		permTreeOriginList = append(permTreeOriginList, permission)
	}
	permTreeList := sysService.PermissionServiceApp.BuildTree(permTreeOriginList)
	response.OkWithData(gin.H{
		"logList":  logList,
		"total":    total,
		"pageNo":   p.PageNo,
		"permList": permTreeList,
	}, c)
}
